<?php
/**
 * Template Name: Manage Courses
 * Description: A Page Template that showcases Sticky Posts, Asides, and Blog Posts
 *
 * The showcase template in Twenty Eleven consists of a featured posts section using sticky posts,
 * another recent posts area (with the latest post shown in full and the rest as a list)
 * and a left sidebar holding aside posts.
 *
 * We are creating two queries to fetch the proper posts and a custom widget for the sidebar.
 *
 * @package WordPress
 * @subpackage Twenty_Eleven
 * @since Twenty Eleven 1.0
 */

// Enqueue showcase script for the slider
get_header(); ?>

<?php
    define('WP_USE_THEMES', false); 
    
    require('DBHandler.php');

    $dbHandler = new DBHandler;
?>

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>
        <h2>Manage Courses</h2>
        <a href="http://students.washington.edu/andreybr/wordpress/?page_id=241">Add new course</a>
        <br/><br/>
        <table border="1">
            <tr>
                <th>Name</th>
                <th>Quarter</th>
                <th>Year</th>
                <th>Faculty</th>
                <th>Edit</th>
                <th>Delete</th>
            </tr>
            <?php
                $rows = $dbHandler->GetAllCourses();

                if ($rows)
                {
                    foreach($rows as $row)
                    {
                        echo "<tr>";
                        echo "<td>" . $row->Name . "</td>";
                        echo "<td>" . $row->Quarter . "</td>";
                        echo "<td>" . $row->Year . "</td>";
                        echo "<td>" . $row->FacultyName . "</td>";
                        echo "<td><a href='http://students.washington.edu/andreybr/wordpress/?page_id=241&op=edit&id=" . $row->Id . "'>Edit</a></td>";
                        echo "<td><a href='http://students.washington.edu/andreybr/wordpress/?page_id=241&op=delete&id=" . $row->Id . "'>Delete</a></td>";
                        echo "</tr>";
                    }
                } 
                else
                {
                    echo "<tr><td colspan=6>No courses found.</td></tr>";
                }
            ?>
        </table>
    </body>
</html>

<?php get_footer() ?>